<template>
  <footer v-if="todos.length" class="todo-footer">
    <input type="checkbox" :checked="allDone" @change="toggleAllDone($event)" />
    <span>已办事项{{ doneCount }}/全部事项{{ allCount }}</span>
    <button @click="clearDone">清除已办</button>
    <button @click="clearAll">清除所有</button>
  </footer>
  <h2 v-else>暂无待办事项</h2>
</template>

<script setup>
import { useTodosStore } from '@/store/todos'
import { storeToRefs } from 'pinia'

const store = useTodosStore()
const { todos, doneCount, allDone, allCount } = storeToRefs(store)
const { clearDone, clearAll, toggleAllDone } = store
</script>

<style scoped>
.todo-footer {
  display: flex;
  margin-top: 20px;
  padding: 10px 40px;
  background-color: #87ceeb;
}

.todo-footer span {
  flex: 1;
  margin-left: 20px;
}

.todo-footer button {
  margin-left: 10px;
  padding-inline: 10px;
  cursor: pointer;
}

h2 {
  text-align: center;
  margin-top: 10px;
}
</style>
